var http = require('http'),
 	Q = require('q'),
	url = require('url'),
	qs = require('querystring');

var HttpPostErpController = require('./HttpPostErp.server.controller.js');

/**
 * 条码解析服务
 * [req]：{Parameter: { "BarCode":"test", "OpType":"1", "DocTypeEnum":"1", "CultureName":"ch-CN","EntCode":"001","OrgCode":"001","UserCode":"101"}}
 * [res]: 根据body中的ifsuccess判断使用 
 			res.bady={
 				ifsuccess : true/false,
    			data : "正确数据或者错误信息"
    		}
 */
exports.getBarCodeInfo=function(req, res){

	var serverParameter = req.body.Parameter;
	if (typeof(serverParameter) === 'string'){
		serverParameter=JSON.parse(serverParameter);
	}

	var context={
		CultureName: serverParameter.CultureName,
		EntCode: serverParameter.EntCode,
		OrgCode: serverParameter.OrgCode,
		UserCode: serverParameter.UserCode
	};

	var params={
		context: context,
		docTypeEnum: serverParameter.DocTypeEnum,
		oPType: serverParameter.OpType,
		barCode: serverParameter.BarCode,
		operateKey: serverParameter.OperationKey
	};

	var option ={url: 'RestServices/UFIDA.U9.BC.Common.IGetDocBarCodeInfoSV.svc/Do'}

    HttpPostErpController.post(option, params, function(result){

    	if(result&&result.IfSuccess){
    		res.json({ Data: result.BarCodeInfo });
    	}else{
    		res.json({ Error: result.ErrorMess });
    	}

    	 res.end();
    })
    
}